package com.yan.service.utils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ClassUtils extends org.apache.commons.lang3.ClassUtils {

    /**
     * 获取当前类 即 当前类的所有父类
     * @param clazz
     */
    public static List<Field> getFieldAll(List<Class<?>> clazz) {
        List<Field> fields = new ArrayList<>();
        for (Class<?> aClass : clazz) {
            Field[] declaredFields = aClass.getDeclaredFields();
            fields.addAll(Arrays.asList(declaredFields));
        }
        return fields;
    }

    /**
     * 获取当前类 即 当前类的所有父类
     */
    public static <T> List<Class<?>> getClassAll(T calzz) {
        List<Class<?>> listSuperClass = new ArrayList<Class<?>>();
        Class<?> superclass = calzz.getClass();
        while (superclass != null) {
            if ("java.lang.Object".equals(superclass.getName())) {
                break;
            }
            listSuperClass.add(superclass);
            superclass = superclass.getSuperclass();
        }
        return listSuperClass;
    }
//        <dependency>
//			<groupId>org.apache.commons</groupId>
//			<artifactId>commons-lang3</artifactId>
//			<version>3.8.1</version>
//		</dependency>
}
